package com.banzhi.shop.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.banzhi.shop.adapter.InnerFragmentPagerAdapter;
import com.banzhi.shop.base.BaseActivity;
import com.banzhi.shop.fragment.HuoDongFragment;
import com.banzhi.shop.fragment.PingTaiFragment;
import com.banzhi.shop.utils.Translucent;
import com.banzhi.shop.view.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * 消息页面
 */
public class NewsActivity extends BaseActivity implements View.OnClickListener {
    /**
     * 退出
     */
    private ImageView ivback;
    /**
     * 平台选项卡
     */
    private TextView tvPT;
    /**
     * 活动选项卡
     */
    private TextView tvHD;
    private NoScrollViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news);
        Translucent.setTranslucent(this);
        setinits();
        setListeners();
    }

    private void setinits() {
        ivback = (ImageView) findViewById(R.id.iv_back);
        tvPT = (TextView) findViewById(R.id.tv_PT);
        tvHD = (TextView) findViewById(R.id.tv_HD);
        viewPager = (NoScrollViewPager) findViewById(R.id.viewpager);

        List<Fragment> fras = new ArrayList<>();
        fras.add(new PingTaiFragment());
        fras.add(new HuoDongFragment());
        InnerFragmentPagerAdapter viewPagerAdapter = new InnerFragmentPagerAdapter(getSupportFragmentManager(), fras);
        viewPager.setAdapter(viewPagerAdapter);
    }

    private void setListeners() {
        ivback.setOnClickListener(this);
        tvPT.setOnClickListener(this);
        tvHD.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_PT:
                tvPT.setBackgroundResource(R.mipmap.bg4);
                tvHD.setBackgroundResource(R.mipmap.bg5);
                tvPT.setTextColor(Color.WHITE);
                viewPager.setCurrentItem(0, false);
                tvHD.setTextColor(ContextCompat.getColor(this, R.color.themeColor));
                break;
            case R.id.tv_HD:
                tvPT.setBackgroundResource(R.mipmap.bg1);
                tvHD.setBackgroundResource(R.mipmap.bg2);
                viewPager.setCurrentItem(1, false);
                tvPT.setTextColor(ContextCompat.getColor(this, R.color.themeColor));
                tvHD.setTextColor(Color.WHITE);
                break;
        }
    }
}
